class Node:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None


class MyLinkedList(object):

    def __init__(self):
        self.c = 0
        self.head = Node(0)
        self.last = Node(0)
        self.head.next = self.last
        self.last.prev = self.head

    def get(self, index):
        """
        :type index: int
        :rtype: int
        """
        if 0 <= index < self.c:
            t = 0
            node = self.head
            while t <= index:
                node = node.next
                t += 1
            return node.val
        else:
            return -1

    def addAtHead(self, val):
        """
        :type val: int
        :rtype: None
        """
        self.c += 1
        node = Node(val)
        next_node = self.head.next
        self.head.next = node
        node.prev = self.head
        node.next = next_node
        next_node.prev = node

    def addAtTail(self, val):
        """
        :type val: int
        :rtype: None
        """
        self.c += 1
        node = Node(val)
        last_node = self.last.prev
        last_node.next = node
        node.prev = last_node
        node.next = self.last
        self.last.prev = node

    def addAtIndex(self, index, val):
        """
        :type index: int
        :type val: int
        :rtype: None
        """
        if index <= self.c:
            t = 0
            node = self.head
            while t < index:
                node = node.next
                t += 1
            next_node = node.next
            new_node = Node(val)
            node.next = new_node
            new_node.prev = node
            new_node.next = next_node
            next_node.prev = new_node
            self.c += 1

    def deleteAtIndex(self, index):
        """
        :type index: int
        :rtype: None
        """
        if 0 <= index < self.c:
            t = 0
            node = self.head
            while t < index:
                node = node.next
                t += 1
            next_node = node.next.next
            node.next = next_node
            next_node.prev = node
            self.c -= 1
